package com.softlab.retailwholesalesystem.controller;

import com.softlab.retailwholesalesystem.entity.RepositoryEntity;
import com.softlab.retailwholesalesystem.service.IRepositoryService;
import com.softlab.retailwholesalesystem.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RepositoryController extends BaseController{

    @Autowired
    IRepositoryService service;

    @RequestMapping("/repository")
    public JsonResult<List<RepositoryEntity>> getAll() {
        List<RepositoryEntity> repository = service.getAllRepository();
        return new JsonResult<>(200,"仓库列表查询成功",repository);
    }

    @RequestMapping("/repository/add")
    public JsonResult<Void> addRepository(RepositoryEntity repository){
        service.addRepository(repository);
        return new JsonResult<>(200,"仓库添加成功");
    }

    @RequestMapping("/repository/delete")
    public JsonResult<Void> deleteRepository(RepositoryEntity repository){
        service.deleteRepository(repository);
        return new JsonResult<>(200,"仓库删除成功");
    }

    @RequestMapping("/repository/update")
    public JsonResult<Void> changeRepository(RepositoryEntity repository){
        service.changeRepository(repository);
        return new JsonResult<>(200,"仓库修改成功");
    }

    @RequestMapping("/repository/search")
    public JsonResult<List<RepositoryEntity>> searchRepositories(RepositoryEntity repository){
        List<RepositoryEntity> list = service.getRepository(repository);
        return new JsonResult<>(200,"仓库搜索成功", list);
    }
}
